package com.jzo2o.market.controller;

import com.jzo2o.common.utils.BeanUtils;
import com.jzo2o.market.model.domain.Activity;
import com.jzo2o.market.model.dto.request.ActivityQueryForPageReqDTO;
import com.jzo2o.market.model.dto.request.ActivitySaveReqDTO;
import com.jzo2o.market.model.dto.response.ActivityInfoResDTO;
import com.jzo2o.market.model.dto.response.ActivityQueryForPageResDTO;
import com.jzo2o.market.service.IActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/*
 *   Description MarketController
 *   @author zhangyan
 *   @time   2024/12/15
 */
@RestController("ActivityController")
@Api(tags = "优惠卷活动服务")
@Slf4j
@RequestMapping("/operation/activity")
public class ActivityController {
    @Autowired
    private IActivityService activityService;

    @PostMapping("/save")
    @ApiOperation("新增和修改优惠券活动")
    public void creatAndUpdateCoupon(@RequestBody ActivitySaveReqDTO dto){
        activityService.creatAndUpdateCoupon(dto);
    }

    @GetMapping("/page")
    @ApiOperation("分页查询优惠卷活动")
    public ActivityQueryForPageResDTO queryPageActivity(ActivityQueryForPageReqDTO dto){
      return   activityService.queryPageActivity(dto);
    }

    @GetMapping("/{id}")
    @ApiOperation("查询优惠卷活动详情")
    public ActivityInfoResDTO getActivityInfo(@PathVariable Long id){
        Activity byId = activityService.getById(id);
        return BeanUtils.copyBean(byId,ActivityInfoResDTO.class);
    }

    @PostMapping("/revoke/{id}")
    @ApiOperation("撤销优惠卷活动")
    public void revokeActivity(@PathVariable Long id){
        activityService.revoke(id);
    }


}
